/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import components.BandShape;
import java.awt.Image;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
/**
 *
 * @author marwa
 */
public class WorkArea extends javax.swing.JInternalFrame {

    Integer[][] markerSample = {{50, 19}};
    int type;

    /**
     * Creates new form EightWorkArea
     */
    public WorkArea(String title) {
        initComponents();
        this.setTitle(title);
        bandsPanel.setBounds(0, 0, 2480, 3500);
    }

    /*
     * This function used to set marker type "ex: 50, 1000 ,etc.."
     */
    public void setMarkerType(int type) {
        this.type = type;
        drawMarker();
    }
    
    int pos;    
    public void setMarkerPos(int pos)
    {
        this.pos = pos;
    }

    /*
     * This function used to draw marker in specified postion on the panel
     */
    private void drawMarker() {
        int samples = 0;
        int nextPos = type;
        
        for (int i = 0; i < markerSample.length; i++) {
            if (markerSample[i][0] == type) {
                samples = markerSample[i][1];
                break;
            }
        }
        for (int i = 0; i < samples; i++) {
            BandShape band = new BandShape();
            Icon icn = new javax.swing.ImageIcon("resources/markers/"+i+".png");
            System.out.println(icn.toString());
            Image img = ((ImageIcon) icn).getImage();
            ImageIcon icon = new ImageIcon(img.getScaledInstance(120, 25, Image.SCALE_AREA_AVERAGING));
            band.setImage(icon);
            band.setSize(120, 25);
            band.setVisible(true);
            band.setLocation(pos, nextPos);
            bandsPanel.add(band);
            bandsPanel.repaint();
            nextPos += type;
        }
    }

    public JPanel getBandsPanel() {
        return bandsPanel;
    }
    
    @Override
    public void doDefaultCloseAction()
    {
        MainFrame frm = (MainFrame)java.awt.Window.getWindows()[0];
        frm.getPCR().getToolbox().dispose();
        this.dispose();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        workAreaScrollPane = new javax.swing.JScrollPane();
        workAreaBackground = new javax.swing.JPanel();
        bandsPanel = new javax.swing.JPanel();

        setClosable(true);

        bandsPanel.setRequestFocusEnabled(false);

        javax.swing.GroupLayout bandsPanelLayout = new javax.swing.GroupLayout(bandsPanel);
        bandsPanel.setLayout(bandsPanelLayout);
        bandsPanelLayout.setHorizontalGroup(
            bandsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 2480, Short.MAX_VALUE)
        );
        bandsPanelLayout.setVerticalGroup(
            bandsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 3508, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout workAreaBackgroundLayout = new javax.swing.GroupLayout(workAreaBackground);
        workAreaBackground.setLayout(workAreaBackgroundLayout);
        workAreaBackgroundLayout.setHorizontalGroup(
            workAreaBackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(workAreaBackgroundLayout.createSequentialGroup()
                .addComponent(bandsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 12, Short.MAX_VALUE))
        );
        workAreaBackgroundLayout.setVerticalGroup(
            workAreaBackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(bandsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        workAreaScrollPane.setViewportView(workAreaBackground);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(workAreaScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 812, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(workAreaScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bandsPanel;
    private javax.swing.JPanel workAreaBackground;
    private javax.swing.JScrollPane workAreaScrollPane;
    // End of variables declaration//GEN-END:variables
}
